<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.ListDocumentoTitle}"></h:outputText>
        </ui:define>

        <ui:define name="body">
            <h:form id="DocumentoListForm">

                <p:growl id="msn" showDetail="true"/>

                <p:tabView id="tabs">

                    <p:ajax event="tabChange" listener="#{documentoController.onTabChange}" update=":DocumentoListForm:msn"/>

                    <p:tab title="Ingresos">

                        <p:commandButton id="createButton" icon="ui-icon-plus" style="margin-bottom: 10px;" value="#{bundle.Create}" action="#{documentoController.prepareCreate}" update=":DocumentoCreateForm" oncomplete="PF('DocumentoCreateDialog').show()"/>

                        <p:panel header="#{bundle.ListDocumentoTitle}">
                            <p:dataTable id="datalist" value="#{documentoController.ingresos}" var="item"
                                         editable="true"
                                         editMode="cell"
                                         rows="1"
                                         >

                                <p:ajax event="cellEdit" listener="#{documentoController.onCellEdit}" update=":DocumentoListForm:msn" />

                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Movimientos"/>
                                    </f:facet>
                                    <center>
                                        <p:commandButton id="createButtonMov" icon="ui-icon-search" actionListener="#{movimientoDocumentoController.cargarMovimientos(item)}" 
                                                         update=":MovimientoDocumentoListForm:datalist, :growl" oncomplete="PF('MovimientoDocumentoCreateDialogMov').show()" style="margin-left: 10px;"/>                                        
                                    </center>
                                </p:column>

                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_fecDoc}"/>
                                    </f:facet>

                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{item.fecDoc}"><f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" /></h:outputText></f:facet>
                                        <f:facet name="input"><p:inputText value="#{item.fecDoc}" style="width:90%"/></f:facet>
                                    </p:cellEditor>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_valorDoc}"/>
                                    </f:facet>

                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{item.valorDoc}"/></f:facet>
                                        <f:facet name="input">
                                            <p:inputText value="#{item.valorDoc}" style="width:90%"/>
                                        </f:facet>
                                    </p:cellEditor>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_anuladoDoc}"/>
                                    </f:facet>
                                    <p:cellEditor>
                                        <f:facet name="output"><p:selectBooleanCheckbox value="#{item.anuladoDoc}"/></f:facet>
                                        <f:facet name="input"><p:selectBooleanCheckbox value="#{item.anuladoDoc}" /></f:facet>
                                    </p:cellEditor>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_notaDoc}"/>
                                    </f:facet>
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{item.notaDoc}"/></f:facet>
                                        <f:facet name="input"><p:inputText value="#{item.notaDoc}" style="width:90%"/></f:facet>
                                    </p:cellEditor>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_consecutivoDoc}"/>
                                    </f:facet>
                                    <h:outputText value="#{item.consecutivoDoc}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_idTipoDocumento}"/>
                                    </f:facet>
                                    <h:outputText value="#{item.idTipoDocumento.prefijoDoc}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_idCliente}"/>
                                    </f:facet>
                                    <h:outputText value="#{item.idCliente.nombre} #{item.idCliente.apellido}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_idTipoDinero}"/>
                                    </f:facet>
                                    <h:outputText value="#{item.idTipoDinero.nombreTipoDinero}"/>
                                </p:column>
                            </p:dataTable>
                        </p:panel>
                    </p:tab>

                    <p:tab title="Egresos">

                        <p:commandButton id="createButtonE" icon="ui-icon-plus" style="margin-bottom: 10px;" value="#{bundle.Create}" actionListener="#{documentoController.prepareCreate}" update=":DocumentoCreateFormE" oncomplete="PF('DocumentoCreateDialogE').show()"/>

                        <p:panel header="#{bundle.ListDocumentoTitle}">
                            <p:dataTable id="datalistE" value="#{documentoController.egresos}" var="iteme"
                                         editable="true"
                                         editMode="cell"
                                         rows="1"
                                         >

                                <p:ajax event="cellEdit" listener="#{documentoController.onCellEdit}" update=":DocumentoListForm:msn" />

                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Movimientos"/>
                                    </f:facet>
                                    <center>
                                        <p:commandButton id="createButtonMovE" icon="ui-icon-search" action="#{movimientoDocumentoController.cargarMovimientosEgresos(iteme)}" 
                                                         update=":MovimientoDocumentoListFormE:datalistE" oncomplete="PF('MovimientoDocumentoCreateE').show()" style="margin-left: 10px;"/>                                        
                                    </center>
                                </p:column>

                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_fecDoc}"/>
                                    </f:facet>

                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{iteme.fecDoc}"><f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" /></h:outputText></f:facet>
                                        <f:facet name="input"><p:inputText value="#{iteme.fecDoc}" style="width:90%"/></f:facet>
                                    </p:cellEditor>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_valorDoc}"/>
                                    </f:facet>

                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{iteme.valorDoc}"/></f:facet>
                                        <f:facet name="input">
                                            <p:inputText value="#{iteme.valorDoc}" style="width:90%"/>
                                        </f:facet>
                                    </p:cellEditor>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_anuladoDoc}"/>
                                    </f:facet>
                                    <p:cellEditor>
                                        <f:facet name="output"><p:selectBooleanCheckbox value="#{iteme.anuladoDoc}"/></f:facet>
                                        <f:facet name="input"><p:selectBooleanCheckbox value="#{iteme.anuladoDoc}"/></f:facet>
                                    </p:cellEditor>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_notaDoc}"/>
                                    </f:facet>
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{iteme.notaDoc}"/></f:facet>
                                        <f:facet name="input"><p:inputText value="#{iteme.notaDoc}" style="width:90%"/></f:facet>
                                    </p:cellEditor>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_consecutivoDoc}"/>
                                    </f:facet>
                                    <h:outputText value="#{item.consecutivoDoc}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_idTipoDocumento}"/>
                                    </f:facet>

                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{iteme.idTipoDocumento.prefijoDoc}"/></f:facet>
                                        <f:facet name="input"><p:inputText value="#{iteme.idTipoDocumento}" style="width:90%"/></f:facet>
                                    </p:cellEditor>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_idCliente}"/>
                                    </f:facet>

                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{iteme.idCliente.nombre} #{iteme.idCliente.apellido}"/></f:facet>
                                        <f:facet name="input"><p:inputText value="#{iteme.idCliente}" style="width:90%"/></f:facet>
                                    </p:cellEditor>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{bundle.ListDocumentoTitle_idTipoDinero}"/>
                                    </f:facet>
                                    <h:outputText value="#{iteme.idTipoDinero.nombreTipoDinero}"/>
                                </p:column>
                            </p:dataTable>
                        </p:panel>
                    </p:tab>
                </p:tabView>
            </h:form>            

            <ui:include src="CreateEgreso.xhtml"/>
            <ui:include src="Create.xhtml"/>
            <ui:include src="CrearMovimiento.xhtml"/>
            <ui:include src="CrearMovimientoEgreso.xhtml"/>

        </ui:define>
    </ui:composition>

</html>
